<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<jsp:include page="../inc.jsp"></jsp:include>
<script type="text/javascript">
	$(function() {
		$('#jzxm_datagrid').datagrid({
			url : '${pageContext.request.contextPath}/school/donateAction!datagrid.action',
			fit : true,
			fitColumns : true,
			border : false,
			rownumbers : true,
			pagination : true,
			idField : 'id',
			singleSelect : true,
			columns : [ [ {
				field : 'id',
				title : '编号',
				width : 100,
				align : 'center',
				checkbox : true
			}, {
				field : 'donateId',
				title : '编号',
				width : 150,
				align : 'center',
				sortable : true
			}, {
				field : 'donor',
				title : '捐赠人（单位）',
				width : 150,
				align : 'center',
				sortable : true
			}, {
				field : 'donateTime',
				title : '捐赠时间 ',
				width : 150,
				align : 'center',
				sortable : true
			}, {
				field : 'donatedItems',
				title : '捐赠事迹',
				width : 350,
				align : 'center',
				sortable : true
			} ] ],
			toolbar : '#jzxm_toolbar',
		});
		$('#jzxm_addTime').datetimebox({
			value : '11/5/2013 2:3',
			required : true,
			showSeconds : false
		});
		$('#jzxm_editTime').datetimebox({
			value : '11/5/2013 2:3',
			required : true,
			showSeconds : false
		});
	});
	function searchFun() {
		$('#jzxm_datagrid').datagrid('load', {
			donor : $('#jzxm_toolbar input[name=donor]').val()
		});
	}
	function clearFun() {
		$('#jzxm_toolbar input[name=donor]').val('');
		$('#jzxm_datagrid').datagrid('load', {});
	}
	function remove() {
		var rows = $('#jzxm_datagrid').datagrid('getChecked');
		var Ids = [];
		if (rows.length > 0) {
			$.messager.confirm('确认', '是否确认删除选中的记录？', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						Ids.push(rows[i].donateId);
					}
					$.ajax({
						url : '${pageContext.request.contextPath}/school/donateAction!remove.action',
						data : {
							Ids : Ids.join(',')
						},
						dataType : 'json',
						success : function(r) {
							$('#jzxm_datagrid').datagrid('load');
							$('#jzxm_datagrid').datagrid('unselectAll');
							$.messager.show({
								title : '提示',
								msg : r.msg
							});
						}
					});
				}
			});
		} else {
			$.messager.alert('提示', '请选择你要操作的行!');
		}
	}
	function add() {
		$('#jzxm_addForm input[name=Donor]').val('');
		$('#jzxm_addForm textarea[name=donatedItems]').val('');
		$('#jzxm_addDialog').dialog('open');
	}
	function edit() {
		$('#jzxm_editForm input').val('');
		var rows = $('#jzxm_datagrid').datagrid('getChecked');
		if (rows.length == 1) {
			$('#jzxm_editForm').form('load',rows[0]);
			$('#jzxm_editDialog').dialog('open');
		} else {
			$.messager.alert('提示', '请选择你要操作一行!');
		}
	}
</script>
</head>
<body>
<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',border:false" style="height:200px;">
		<table id="jzxm_datagrid"></table>
	</div>
</div>
<div id="jzxm_toolbar" class="easyui-toolbar" style="background:#f9f9f9;">
	<table>
		<tr>
			<td style="padding:10px 5px 3px 15px;">捐赠人(单位) ：<input id="jzxm_donorCmb" name="donor" style="width:100px;" />
			</td>
		</tr>
	</table>
	<table>
		<tr>
			<td style="padding:3px 5px 3px 5px;"><a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add()">添加</a>
			</td>
			<td style="padding:3px 5px 3px 5px;"><a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit()">编辑</a>
			</td>
			<td style="padding:3px 5px 3px 5px;"><a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="remove()">删除</a>
			</td>
			<td style="padding:3px 5px 3px 5px;"><a href="#" class="easyui-linkbutton" data-options="border:false,iconCls:'icon-search',plain:true" onclick="searchFun()">查询</a>
			</td>
			<td style="padding:3px 5px 3px 5px;"><a href="#" class="easyui-linkbutton" data-options="border:false,iconCls:'icon-ext-bullet_cross',plain:true" onclick="clearFun()">清空</a>
			</td>
		</tr>
	</table>
</div>
<div id="jzxm_addDialog" class="easyui-dialog"  data-options="width:470,height:250,modal:true,closed:true,title:'添加',
			buttons : [ {
				text : '确定',
				iconCls : 'icon-ok',
				handler : function() {
					$('#jzxm_addForm').form('submit', {
						url : '${pageContext.request.contextPath}/school/donateAction!add.action',
						success : function(r) {
							var obj = jQuery.parseJSON(r);
							if (obj.success) {
								$('#jzxm_datagrid').datagrid('load');
								$('#jzxm_addDialog').dialog('close');
							}
							$.messager.show({
								title : '提示',
								msg : obj.msg
							});
						}
					});
				}
			} ]"> 
	<form id="jzxm_addForm" method="post">
		<table>
			<tr>
				<td style="padding:10px 5px 5px 40px;">捐赠人(单位)：</td>
				<td><input type="text" name="Donor" class="easyui-validatebox" data-options="required:true,validType:'length[0,50]',missingMessage:'请输入捐赠人(单位)！'"/>
				</td>
			</tr>
			<tr>
				<td style="padding:10px 5px 5px 40px;">捐赠时间：</td>
				<td><input type="text" id="jzxm_addTime" name="DonateTime">
				</td>
			<tr>
			<tr>
				<td style="padding:10px 5px 5px 40px;">捐赠项目：</td>
				<td><textarea rows="2" cols="15" name="donatedItems" class="easyui-validatebox" data-options="required:true,validType:'length[0,200]',missingMessage:'请输入捐赠项目！'"></textarea>
				</td>
			<tr>
		</table>
	</form>
</div>
<div id="jzxm_editDialog" class="easyui-dialog" data-options="width:470,height:250,modal:true,closed:true,title:'编辑',
			buttons : [ {
				text : '确定',
				iconCls : 'icon-ok',
				handler : function() {
					$('#jzxm_editForm').form('submit', {
						url : '${pageContext.request.contextPath}/school/donateAction!edit.action',
						success : function(r) {
							var obj = jQuery.parseJSON(r);
							if (obj.success) {
								$('#jzxm_datagrid').datagrid('load');
								$('#jzxm_editDialog').dialog('close');
							}
							$.messager.show({
								title : '提示',
								msg : obj.msg
							});
						}
					});
				}
			} ]">
	<form id="jzxm_editForm"  method="post">
		<table>
			<tr style="display:none">
				<td style="padding:10px 5px 5px 40px;">捐赠编号：</td>
				<td><input type="text" name="donateId" readonly="readonly"/>
				</td>
			</tr>
			<tr>
				<td style="padding:10px 5px 5px 40px;">捐赠人(单位)：</td>
				<td><input type="text" name="donor" class="easyui-validatebox" data-options="required:true,validType:'length[0,50]',missingMessage:'请输入捐赠人(单位)！'" />
				</td>
			</tr>
			<tr>
				<td style="padding:10px 5px 5px 40px;">捐赠时间：</td>
				<td><input type="text" id="jzxm_editTime" name="donateTime">
				</td>
			<tr>
			<tr>
				<td style="padding:10px 5px 5px 40px;">捐赠项目：</td>
				<td><textarea rows="2" cols="15" name="donatedItems" class="easyui-validatebox" data-options="required:true,validType:'length[0,200]',missingMessage:'请输入捐赠项目！'"></textarea>
				</td>
			<tr>
		</table>
	</form>
</div>
</body>
</html>

